package com.atguigu.juc.interview.cf;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

/**
 * @author : leimingchao
 * @date Date : 2021年09月30日 21:26
 */
public class CompletableFutureNetMallDemo {

    public static void main(String[] args) {

        System.out.println(CompletableFuture.supplyAsync(() -> {
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return 1;
        }).whenComplete((v, e) -> {
            if (e == null) {
                System.out.println("----result:" + v);
            }
        }).exceptionally(e -> {
            e.printStackTrace();
            return null;
        }).join());


        System.out.println("------ main thread over");
        try {
            TimeUnit.SECONDS.sleep(3);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
